<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_pegawai extends CI_Controller {

	function __construct() {
        parent::__construct();	
		$this->load->model("master/master_pegawai"); 		
	}
	
	function index()
	{
		$data['judul'] = "Master Pegawai";
		$data['list'] = $this->master_pegawai->read();
		$data['main_view']='master/pegawai/pegawai';
		$this->load->view('index',$data);	
	}

	function save()
	{
		$tgl_lahir = $this->input->post('tgl_lahir');
		$dateLahir = str_replace('/', '-', $tgl_lahir);
		$tglMySQLL = date('Y-m-d', strtotime($dateLahir));

		$dataInsert = array(
			'nama_lengkap' => $this->input->post('nama_lengkap'),
			'tmp_lahir' => $this->input->post('tmp_lahir'),
			'tgl_lahir' => $tglMySQLL,
			'no_tlp' => $this->input->post('no_tlp'),
			'email' => $this->input->post('email'),
			'alamat' => $this->input->post('alamat')
		);
		$this->master_pegawai->save($dataInsert);
	}

	function edit()
	{
		$id_m_pegawai = $this->input->post('id_m_pegawai');
		$data['list']=$this->master_pegawai->edit($id_m_pegawai);	
		$this->load->view('master/pegawai/edit',$data);
	}
	
	function update()
	{	
		$id_m_pegawai=$this->input->post('id_m_pegawai');
		
		$tgl_lahir = $this->input->post('tgl_lahir');
		$dateLahir = str_replace('/', '-', $tgl_lahir);
		$tglMySQLL = date('Y-m-d', strtotime($dateLahir));

		$dataUpdate=array(
			'nama_lengkap' => $this->input->post('nama_lengkap'),
			'tmp_lahir' => $this->input->post('tmp_lahir'),
			'tgl_lahir' => $tglMySQLL,
			'no_tlp' => $this->input->post('no_tlp'),
			'email' => $this->input->post('email'),
			'alamat' => $this->input->post('alamat')
		);		
		$this->master_pegawai->update($id_m_pegawai,$dataUpdate);
	}

	function delete()
	{
		$id_m_pegawai = $this->input->post('id_m_pegawai');
		$this->master_pegawai->delete($id_m_pegawai);
	}
	
	function refresh()
	{
		$data['list'] = $this->master_pegawai->read();
		$this->load->view('master/pegawai/refresh', $data);
		
	}

	function detail()
	{
		$id_m_pegawai = $this->input->post('id_m_pegawai');
		$data['list']=$this->master_pegawai->edit($id_m_pegawai);	
		$this->load->view('master/pegawai/detail',$data);
	}
	
}